package com.l2jserver.gameserver.communitybbs;

import com.l2jserver.Config;
import com.l2jserver.gameserver.communitybbs.Manager.ClanBBSManager;
import com.l2jserver.gameserver.communitybbs.Manager.FavoriteBBSManager;
import com.l2jserver.gameserver.communitybbs.Manager.FriendsBBSManager;
import com.l2jserver.gameserver.communitybbs.Manager.HomeBBSManager;
import com.l2jserver.gameserver.communitybbs.Manager.HomePageBBSManager;
import com.l2jserver.gameserver.communitybbs.Manager.PostBBSManager;
import com.l2jserver.gameserver.communitybbs.Manager.RegionBBSManager;
import com.l2jserver.gameserver.communitybbs.Manager.TopicBBSManager;
import com.l2jserver.gameserver.communitybbs.Manager.Casino.BlackJack.BlackJackBBSManager;
import com.l2jserver.gameserver.communitybbs.Manager.Casino.SlotMachine.SlotMachineBBSManager;
import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
import com.l2jserver.gameserver.network.L2GameClient;
import com.l2jserver.gameserver.network.serverpackets.ShowBoard;

public class CommunityBoard
{
	public void handleCommands(L2GameClient client, String command)
	{
		L2PcInstance activeChar = client.getActiveChar();
		if (activeChar == null)
		{
			return;
		}
		
		if (command.startsWith("_bbsgetfav") && Config.ENABLE_FAVORITE)
		{
			FavoriteBBSManager.getInstance().parseCmd(command, activeChar);
		}
		else if (command.startsWith("_bbsclan") && Config.ENABLE_CLAN)
		{
			ClanBBSManager.getInstance().parseCmd(command, activeChar);
		}
		else if (command.startsWith("_bbsmemo") && Config.ENABLE_MAIL)
		{
			TopicBBSManager.getInstance().parseCmd(command, activeChar);
		}
		else if (command.startsWith("_bbstopics") && Config.ENABLE_MAIL)
		{
			TopicBBSManager.getInstance().parseCmd(command, activeChar);
		}
		else if (command.startsWith("_bbsposts"))// FIXME
		{
			PostBBSManager.getInstance().parseCmd(command, activeChar);
		}
		else if (command.startsWith("_bbslink") && Config.ENABLE_HOMEPAGE)
		{
			HomePageBBSManager.getInstance().parseCmd(command, activeChar);
		}
		else if (command.startsWith("_bbshome") && Config.ENABLE_HOME)
		{
			HomeBBSManager.getInstance().parseCmd(command, activeChar);
		}
		else if (command.startsWith("_bbsloc") && Config.ENABLE_REGION)
		{
			RegionBBSManager.getInstance().parseCmd(command, activeChar);
		}
		else if (command.startsWith("_friend") && Config.ENABLE_FRIENDS)
		{
			FriendsBBSManager.getInstance().parseCmd(command, activeChar);
		}
		else if (command.startsWith("_bbsslot"))// Casino
		{
			SlotMachineBBSManager.getInstance().parseCmd(command, activeChar);
		}
		else if (command.startsWith("_bbsblack"))// Casino
		{
			BlackJackBBSManager.getInstance().parseCmd(command, activeChar);
		}
		else
		{
			ShowBoard sb = new ShowBoard("<html><body><br><br><center>the command: " + command + " is not implemented yet</center><br><br></body></html>", "101");
			activeChar.sendPacket(sb);
			activeChar.sendPacket(new ShowBoard(null, "102"));
			activeChar.sendPacket(new ShowBoard(null, "103"));
		}
	}
	
	/**
	 * @param client
	 * @param url
	 * @param arg1
	 * @param arg2
	 * @param arg3
	 * @param arg4
	 * @param arg5
	 */
	public void handleWriteCommands(L2GameClient client, String url, String arg1, String arg2, String arg3, String arg4, String arg5)
	{
		L2PcInstance activeChar = client.getActiveChar();
		
		if (activeChar == null)
		{
			return;
		}
		
		if (url.equals("Topic") && Config.ENABLE_MAIL)
		{
			TopicBBSManager.getInstance().parseWrite(arg1, arg2, arg3, arg4, arg5, activeChar);
		}
		else if (url.equals("Post"))
		{
			PostBBSManager.getInstance().parseWrite(arg1, arg2, arg3, arg4, arg5, activeChar);
		}
		else if (url.equals("Region") && Config.ENABLE_REGION)
		{
			RegionBBSManager.getInstance().parseWrite(arg1, arg2, arg3, arg4, arg5, activeChar);
		}
		else if (url.equals("Notice") && Config.ENABLE_CLAN)
		{
			ClanBBSManager.getInstance().parseWrite(arg1, arg2, arg3, arg4, arg5, activeChar);
		}
		else if (url.equals("_friend") && Config.ENABLE_FRIENDS)
		{
			FriendsBBSManager.getInstance().parseWrite(arg1, arg2, arg3, arg4, arg5, activeChar);
		}
		else
		{
			ShowBoard sb = new ShowBoard("<html><body><br><br><center>the command: " + url + " is not implemented yet</center><br><br></body></html>", "101");
			activeChar.sendPacket(sb);
			activeChar.sendPacket(new ShowBoard(null, "102"));
			activeChar.sendPacket(new ShowBoard(null, "103"));
		}
		
	}
	
	public static CommunityBoard getInstance()
	{
		return SingletonHolder._instance;
	}
	
	private static class SingletonHolder
	{
		protected static final CommunityBoard _instance = new CommunityBoard();
	}
}